#ifndef OBJECT_MANAGER_H
#define OBJECT_MANAGER_H

#pragma once

#include "singleton.h"

class sgEntity;
class sgObject;
struct sgMessage;
typedef std::map<int, sgObject*> ObjectMap; 
typedef sgObject * (*ObjectCreator)(void);
typedef std::map<int, ObjectCreator> CreatorMap; 
typedef std::vector<sgEntity*> EntityVec;
typedef std::queue<sgMessage*> MessagePool;
class guiMediator;
class CObjectManager:public CSingleton<CObjectManager>
{
	IMPLEMENT_SINGLETON( CObjectManager );
public:
	void Update( int diff );
    void Render( );
    void DeleteAllObj( );
    sgObject *CreateObject( int classtype );
    ObjectCreator GetCreator( int classtype );
    bool RegisteCreator( int classtype, ObjectCreator creator );
	
    bool AddObject( sgObject *obj );
    bool RemoveObject( sgObject *obj );
    sgObject *GetObject( int id );
    int GenerateObjectID( );
    void CheckSelected( );
    void SendMessage( sgMessage *msg );
    void SendMessageToGUI( sgMessage *msg );
    void DispatchMessage( );
    void AddSelectedEntity( sgEntity *entity );
    guiMediator *GetGuiMediator( );
    void SetGuiMediator( guiMediator *m );

    void SaveObjects( );
    void LoadObjects( );
private:
    ObjectMap m_objects;
    CreatorMap m_creators;
    EntityVec m_selectedEntities;
    int m_curObjId;
    MessagePool m_messages;
    guiMediator *m_guimediator;
};

#endif